<!DOCTYPE html>
<html lang="en">

<head>
  <meta charset="UTF-8">
  <meta http-equiv="X-UA-Compatible" content="IE=edge">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <title>Document</title>
</head>
<script>
  const p = new Promise((resolve, reject) => {
    //初始化
    const x = new XMLHttpRequest()
    //f发送请求
    x.open('Get', 'https://api.apiopen.top/getJoke')
    //发送请求
    x.send()
    x.onreadystatechange = function () {
      if (x.readyState === 4) {
        if (x.status >= 200 && x.status < 300) {
          resolve(x.response)
        } else {
          reject(x.status)
        }
      }
    }

  })
  const res = p.then(function (value) {
    return new Promise((resolve, reject) => {
      throw '出错了'
    })
  }, function (reason) {
    console.log(reason)
  }).catch(function (err) {
    return err
  })
  p.then(function (value) {
    console.log(value)
    return new Promise((res, rej) => {
      res('promise2')
    })
  }, function (err) {}).then(function (val) {
    console.log(val)
  }, function (err) {})
  console.log(p)
</script>

<body>

</body>

</html>